package socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author DBX
 * @effect
 * @date 2021/8/30 0030 - 20:39
 */
public class Server1 {
    private ServerSocket serverSocket;
    public Server1(){
        try {
            System.out.println("服务端正在启动。。。");
            serverSocket = new ServerSocket(8088);
            System.out.println("服务端启动成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public void start(){
        try {
            System.out.println("等待服务端连接");
            Socket socket = serverSocket.accept();
            System.out.println("一个客户的连接了");

            BufferedReader br = new BufferedReader(
                    new InputStreamReader(socket.getInputStream(),"UTF-8"));
            while (true){
                String message = br.readLine();
                System.out.println("客户端说："+message);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        Server server = new Server();
        server.start();
    }
}
